package 热浪;

import java.util.*;

public class Main {
    //除了起点和终点外的每个城镇都由 双向道路 连向至少两个其它的城镇。
    static int N = 2510, M = 6200 * 2 + 10, n, m, start, end, idex;
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[] ne = new int[M];
    static int[] w = new int[M];
    static boolean[] st = new boolean[N];
    static int[] dist = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        start = in.nextInt();
        end = in.nextInt();
        Arrays.fill(dist, Integer.MAX_VALUE);
        Arrays.fill(h, -1);
        for (int i = 0; i < m; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        spfa();
        System.out.println(dist[end]);
    }

    private static void spfa() {
        Queue<Integer> q = new LinkedList<>();
        q.offer(start);
        st[start] = true;
        dist[start] = 0;
        while (!q.isEmpty()) {
            int t = q.poll();
            st[t] = false;
            for (int i = h[t]; i != -1; i = ne[i]) {
                int j = e[i];
                if (dist[j] > dist[t] + w[i]) {
                    dist[j] = dist[t] + w[i];
                    if (!st[j]) {
                        q.offer(j);
                        st[j] = true;
                    }
                }
            }
        }
    }

    private static void add(int a, int b, int c) {
        e[idex] = b;
        w[idex] = c;
        ne[idex] = h[a];
        h[a] = idex++;
    }
}